package com.ibm.sample.library.web.action;

import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.ibm.sample.library.model.Category;
import com.ibm.sample.library.service.IService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@ParentPackage("json-default")
@Result(name = "success", type = "json", params = { "root", "category" })
public class UpdateCategoryAction extends ActionSupport implements ModelDriven<Category>
{
    private static final long serialVersionUID = 1L;

    @Autowired
    private IService service;

    private Category category = new Category();

    @Override
    public String execute() throws Exception
    {
        service.updateCategory(category);

        return SUCCESS;
    }

    @Override
    public Category getModel()
    {
        return category;
    }

    public Category getCategory()
    {
        return category;
    }

    public void setCategory(Category category)
    {
        this.category = category;
    }
}
